
#HLA EPITOPES FREQUENCY DATABASE
#Function: Insert data into [epit_loci] table [EpitHLA] schema
#Created in: 29.01.2014
#Author: Louise Takeshita


use strict;
use EpiHash qw(epi_data);

#Process Epitope data into HashMap
my %epitopes = epi_data; # returns epitope hashmap

#Create output file
open(OUTPUT,">insert_epitloci.sql") || die "The file insert_epitloci.sql could not be opened.\n"; #open file and handle unexpected errors

#Processing
for my $ep ( sort { $epitopes{$a}{'pos'} <=> $epitopes{$b}{'pos'}} keys %epitopes )
	{
	my $epit_id = $epitopes{$ep}{'pos'};
	if(exists $epitopes{$ep}{'A'})
		{
		print OUTPUT "INSERT INTO EpitHLA.epit_loci VALUES ($epit_id,'A');\n";
		}
	if(exists $epitopes{$ep}{'B'})
		{
		print OUTPUT "INSERT INTO EpitHLA.epit_loci VALUES ($epit_id,'B');\n";
		}
	if(exists $epitopes{$ep}{'C'})
		{
		print OUTPUT "INSERT INTO EpitHLA.epit_loci VALUES ($epit_id,'C');\n";
		}
	}
			
print "Done!";